package com.zx.cloud.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.common.filter.IgnoreAuth;
import com.zx.cloud.domain.VerifyEntity;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.model.response.Response;
import com.zx.cloud.service.VerifyEquipmentService;
import com.zx.cloud.service.VerifyMsgService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @Description:
 *
 * @author       Yan Weiwei
 * @Create Time: 2017年10月28日下午2:14:14
 */

@RestController
@RequestMapping(value = ApiVersion.PROVIDER_V1_PREFIX+"/verify")
public class VerificationController {

	private static final Logger logger=Logger.getLogger(VerificationController.class);
	
	@Autowired
	private VerifyMsgService verifyMsgService;
	
	@Autowired
	private VerifyEquipmentService  verifyEquipmentService;
	
	@IgnoreAuth
	@ApiOperation(value = "身份OCR认证", notes = "身份OCR认证")
	@RequestMapping(value = "/idcardOcr", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<String> idcardOcr(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId, @RequestBody VerifyEntity verifyEntity){
		
		logger.info("******************************根据文件路径："+ verifyEntity.getFilePath() +"获取********************************");
		String success = verifyMsgService.handleVerification(verifyEntity.getFilePath(), userId);
		
		return new ObjectDataResponse<String>(success);
	}
	
	@IgnoreAuth
	@ApiOperation(value = "身份活体检测", notes = "身份活体检测")
	@RequestMapping(value = "/checkLiveness", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<String> checkLiveness(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId, @RequestBody VerifyEntity verifyEntity){
		
		logger.info("******************************根据文件路径："+ verifyEntity.getFilePath() +"获取********************************");
		logger.info("******************************根据url路径："+ verifyEntity.getFileUrl() +"获取********************************");
		String success = verifyMsgService.handleCheckLiveness(verifyEntity.getFilePath(), verifyEntity.getFileUrl(), verifyEntity.getFileId());
		
		return new ObjectDataResponse<String>(success);
	}
	
	@IgnoreAuth
	@RequestLogging
	@ApiOperation(value = "校验IP、设备黑名单" , notes = "校验IP、设备黑名单")
	@RequestMapping(value = "verifyEquipment", method = RequestMethod.POST)
	@ResponseBody
	public Response verifyEquipment(@RequestBody VerifyEntity verifyEntity){
		int success = verifyEquipmentService.verifyEquipment(verifyEntity);
		return new ObjectDataResponse<Integer>(success);
	}
}
